export default {
	provide() { // 这里定义provide 传递参数
		return {
			data: this.data || {}, // 表格数据
			pagination: this.pagination, // 分页属性
			// del_data_dialog: this.del_data_dialog || false// 删除数据的开关
		}
	},
	data() {
		return {
			// 分页
			data: [],
			table_max_height: '600',
			header_cell_style: {
				background: '#003366',
				color: '#fff'
			},
			pagination: {
				currentPage: 1,
				pageSize: 10,
				banNext: false
			},
			pageSizeData: {},
			loading: false, // 加载
			drawer_form: false,
			del_data_dialog: false,
			delData: {},

			// mobile
			mobile_table_max_height: '500'
			
		}
	},
	methods: {
		// 新增表单
		addForm() {
			let self = this;
			self.drawer_form = true;
		},
		getDrawerForm(data) {
			let self = this;
			self.drawer_form = data.child_drawer_form;
			self.initForm();
		},
		// 重置表单填写
		resetForm(formName) {
			let self = this;
			self.$refs[formName].resetFields();
			self.initForm();
		},
		// 删除数据
		onDelData(row) {
			let self = this;
			self.del_data_dialog = true;
			self.delData = row;
		},
		// 查看删除的数据
		getDelData(data) {
			let self = this;
			self.del_data_dialog = data.child_del_data_dialog;
			self.submitDeleteData(self.delData.id);
		},
		// 取消删除数据
		getCancelDelData(data) {
			let self = this;
			self.del_data_dialog = data.child_del_data_dialog;
		},
		submitSuccess() {
			let self = this;
			self.$message.success("提交成功");
		},
		delSuccess() {
			let self = this;
			self.$message.success("删除成功");
		},
		// 分页
		onGotPageData(data) {
			let self = this;
			self.loading = false;
			let tableData = data.data.data;
			if (tableData.total) {
				self.data = tableData.data;
				self.showData(self.data, data);
			} else if (!tableData.total) {
				self.data = tableData;
				self.showData(self.data, data);
			}
		},
		showData(val, resData) {
			let self = this;
			if (val.length > 0) {
				self.pageSizeData = resData.config.params;
				self.pagination.currentPage = self.pageSizeData.page;
				self.pagination.pageSize = self.pageSizeData.limit;
			} else {
				self.$message.warning("暂无更多信息");
				self.pagination.banNext = true;
			}
		},
		onPageChanged({
			currentPage,
			pageSize,
			banNext
		}) {
			this.pagination.currentPage = currentPage;
			this.pagination.pageSize = pageSize;
			this.pagination.banNext = banNext;
			if (this.getData) {
				this.getData();
			}
		},
		addPageInfo(params = {}) {
			Object.assign(params, {
				pageSize: this.pagination.pageSize,
				pageNumber: this.pagination.currentPage
			})
			return params;
		},
		// 搜索数据
		addSearchPageInfo() {
			this.pagination.currentPage = 1;
			this.pagination.pageSize = 10;
			this.pagination.banNext = false;
		},
		// 搜索数据
		getSearchData() {
			let self = this;
			self.addSearchPageInfo();
			self.getData();
		},
		// 刷新
		onRefresh() {
			window.location.reload();
		}
	}
}
